<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<link href="js/themes/icon.css" rel="stylesheet" />
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<%
	String id = (String) request.getAttribute("id");
%>
<html>
<head>

<script type="text/javascript">
var id=<%=id%>;
var listPageUrl="user/index.do";
var userInfoUrl="rest/userInfo.do";
var updateUserUrl="rest/userUpdate.do";

$(document).ready(function () {	
	
     $('#userpasswd-fm').form('load', userInfoUrl+"?id="+id);
     $.extend($.fn.validatebox.defaults.rules, {    
    	    comparetext: {    
    	        validator: function(value, param){    
    	            return value == $(param[0]).val();    
    	        },    
    	        message: '确认密码与新密码不一致！'   
    	    }    
    	}); 
})//end ready

function updateUser() {
	if(!$("#userpasswd-fm").form('validate')){
		return;
	}
	$.post("rest/checkuser.do",{"id":$("#userId").val(),"userpasswd":$("#olduserpasswd").val()},function(data){
		if(data.retCode=='0000'){
			
			$.post(updateUserUrl,{"id":$("#userId").val(),"userpasswd":$("#newuserpasswd").val()},function(result){
                   if (result.retCode=='0000') {
                   	$.messager.alert('操作提示', "修改成功", 'info');
                   	window.location = "login.jsp";
                   }else {
                       $.messager.alert("提示",result.retMsg);
                   }
	        });
		}else{
			$.messager.show({
                title: 'Error',
                msg: '原始密码输入错误'
            });
		}
		
	});	
    
}
function back(){
	var backUrl = "todo/index.do";
	$.get(backUrl, {}, function(data){
		$("#center").empty();
        $("#center").html("每天工作好心情。");
        $.parser.parse($("#center"));
    });
}
</script>
</head>
<body>
<!-- 		<div class="breadcrumb"> 编辑密码</div> -->
		<div id="userpasswd-update" 	buttons="#userpasswd-update-buttons">
			<form id="userpasswd-fm" method="post" novalidate>
				<INPUT TYPE="hidden" id="userId" NAME=id VALUE="<%=id%>">
				<%--<INPUT TYPE="hidden" NAME="userpasswd" >
				--%><%--<div class="fitem">
					<label>用户名称:</label> 
					<input name="username"  class="easyui-textbox" disabled style="width: 200px;" />
				</div>
				--%>
				<div class="fitem">
					<label>原密码:</label> 
					<input id="olduserpasswd"  type="password" name="olduserpasswd"  class="easyui-validatebox" data-options="required:true" style="width: 200px;"  />
				</div>
				<div class="fitem">
					<label>新密码:</label> 
					<input id="newuserpasswd" type="password" name="userpasswd"  class="easyui-validatebox" data-options="required:true" style="width: 200px;"  />
				</div>
				<div class="fitem">
					<label>确认密码:</label> 
					<input id="comfirmuserpasswd" type="password" name="comfirmuserpasswd"  class="easyui-validatebox" required="required" validType="comparetext['#newuserpasswd']"  style="width: 200px;"  />
				</div>
			</form>
		</div>
		<div id="dlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok"  onclick="updateUser()">保存</a> 
			<!-- <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="back()">返回</a> -->
		</div>
		

</body>
</html>